package Dji;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * Description：
 * Author: zhangc
 * Date：2017/9/14 12:04
 */
public class Num {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in

        );
        int n1 = in.nextInt();
        int m1 = in.nextInt();

        int[] arr = new int[ n1 ];
        for (int i = 0; i < n1; i++) {
            arr[ i ] = in.nextInt();
        }

        ArrayList<Integer> p = new ArrayList<>(m1);
        for (int i = 0; i < m1; i++) {
            p.add(in.nextInt());
        }
        int total = 0, i2, i3, i4;
        for (int i = 0; i < arr.length; i++) {
            for (int j = i; j < arr.length; j++) {
                int i1 = maxCommonDivisor2(arr[ i ], arr[ j ]);
                for (Integer integer : p) {
                    i2 = integer / i1;
                    i3 = arr[ i ] / i1;
                    i4 = arr[ j ] / i1;
                    if (i2 == i3 + i4)
                        total++;
                }
            }
        }
        System.out.println(total);
    }


    // 循环法求最大公约数
    public static int maxCommonDivisor2(int m, int n) {

        if (m < n) {// 保证m>n,若m<n,则进行数据交换
            int temp = m;
            m = n;
            n = temp;
        }
        while (m % n != 0) {// 在余数不能为0时,进行循环
            int temp = m % n;
            m = n;
            n = temp;
        }
        return n;// 返回最大公约数
    }

}
